package com.jdd.modules.sdk.rs485Callback;

import com.jdd.common.constant.CacheConstant;
import com.jdd.common.constant.JddConstant;
import com.jdd.common.util.CacheUtil;
import com.jdd.modules.sdk.SdkCallInterface;
import com.jdd.modules.sdk.utils.FeiLiDeLedUtils;
import com.jdd.modules.sdk.utils.ZHENSHISDK;
import com.sun.jna.Pointer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Description:
 * @author： jdd尚岳
 * @Date: 2022-04-21 11:40
 */
@Component
public class ZhenShi485Callback implements ZHENSHISDK.VZDEV_SERIAL_RECV_DATA_CALLBACK{
    @Resource
    SdkCallInterface sdkCallInterface;
    @Resource
    CacheUtil cacheUtil;
     @Override
    public void invoke(int handle, Pointer pRecvData, int uRecvSize, Pointer pUserData) {

           //获取内存数据
         byte[] byteArray = pRecvData.getByteArray(0, uRecvSize);
         //将byte数组转16进制
             String str = FeiLiDeLedUtils.bytes2HexString(byteArray);
             System.out.println(str);
             String substring=null;
             //判断字符串是否满足截取需求
             if (null!=str && str.length()>=22){
                 substring = str.substring(0, 22);
             }else {
                 substring=str;
             }
             //判断此条指令是否是遥控开闸
              if (JddConstant.DaoZha.REMOTE_CONTROL.equals(substring)){
                 //根据句柄获取设备序列号

                 String serialNo = cacheUtil.get(CacheConstant.GET_SERIAL_HANDLE_SERIALNO, String.valueOf(handle));
                 cacheUtil.put(CacheConstant.EMOTE_PENED,serialNo, serialNo);
                 //进行触发识别
                 sdkCallInterface.TriggerExtAll(serialNo);
             }



     }
}
